#include <iostream>
#include <string>
#include <stack>
using namespace std;
int main() {
    string a;
    cout << "Введите скобочную последовательность:";
    cin >> a;
    stack<char> stack;
    bool isValid = true;

    for (char C : a) {
        if (C == '(' or C == '[' or C == '{' or C == '<') {
            stack.push(C);
        } else if (C == ')' or C == ']' or C == '}' or C == '>') {
            if (!stack.empty()) {
                char top = stack.top();
                if ((C == ')' and top == '(') or
                    (C == ']' and top == '[') or
                    (C == '}' and top == '{') or
                    (C == '>' and top == '<')) {
                    stack.pop();
                } else {
                    isValid = false;
                    break;
                }
            } else {
                isValid = false;
                break;
            }
        }
    }

    if (isValid and stack.empty()) {
        cout << "true" << std::endl;
    } else {
        cout << "false" << std::endl;
    }

    return 0;
}

